<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
         <el-form-item label="姓名" prop="user_name">
  <el-input v-model="query.user_name" name="user_name" clearable />
</el-form-item>

<el-form-item label="openid" prop="openid">
  <el-input v-model="query.openid" name="openid" clearable />
</el-form-item>

<el-form-item label="手机号" prop="phone">
  <el-input v-model="query.phone" name="phone" clearable />
</el-form-item>

<el-form-item label="性别 1 男， 2 女" prop="sex">
  <el-radio-group v-model="query.sex">
    <el-radio v-for="item in options" :key="item.value" :label="item.value" name="sex">{{ item.label }}</el-radio>
  </el-radio-group>
</el-form-item>

<el-form-item label="注册ip" prop="register_ip">
  <el-input v-model="query.register_ip" name="register_ip" clearable />
</el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <Operate :show="open" />
      <el-table :data="tableData" class="mt-3" v-loading="loading" >
        <el-table-column prop="status" label="用户状态 1 正常，2禁用" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <Update @click="open(scope.row.id)" />
            <Destroy @click="destroy(api, scope.row.id)" />
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '@/composables/curd/useGetList'
import { useDestroy } from '@/composables/curd/useDestroy'
import { useOpen } from '@/composables/curd/useOpen'

const api = '/user/user'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

onMounted(() => {
  search()
  deleted(reset)
})
</script>
